#! /usr/bin/env python
# -*- coding: utf-8 -*-
"""



:History:

Created on Mon Jan 26 12:19:07 2015

@author: azzollini
"""

from __future__ import absolute_import, unicode_literals, division, print_function

from pdb import set_trace as stop

import numpy as np

from pySkySim.losvd_lib import kepler
from pySkySim import radial as rad

class Losvd(object):
    """Line-of-Sight Velocity Distribution Class"""
    
    def __init__(self,sigma,h3=0,h4=0):
        """ """
        self.sigma = sigma
        self.h3 = h3
        self.h4 = h4
        
    def __call__(self,v):
        """ """
        sigma = self.sigma
        h3 = self.h3
        h4 = self.h4
        print('MISSING:modified gaussian LOSVD')
        return v * 0.


class VeloMap(object):
    """ """
    
    def __init__(self):
        """ """
        
    def __call__(self,Pos):
        return self.vmapfunct(Pos)
        
    def losvd(self,x):
        """ 
        x : c Ln lambda
        """
        
        sigma = self.sigma
        h3 = self.h3
        h4 = self.h4
        print('MISSING:modified gaussian LOSVD(x=cLnlambda)')
        return x * 0.
        
    def set_losvd(self,sigma,h3=0,h4=0):
        """ """
        self.sigma = sigma
        self.h3 = h3
        self.h4 = h4

class KinoDisk(VeloMap):
    """ """
    
    def __init__(self,Cen=(0.,0.),pa=0,q=1,c=0,Type=None,Vsys=0):
        """ """
        super(KinoDisk,self).__init__()
        
        self.Type = Type
        self.Cen = Cen
        self.pa = pa
        self.q = q
        self.c = c
        
        self.vsys = 0
        
    
    def vmapfunct(self,Pos):
        """ """
        
        npoints = len(Pos)
        vmap = np.zeros(npoints,dtype='float64')
        
        radii = rad.dist_mask(Pos,self.Cen,self.pa,self.q,self.c)        
        
        phi = self.getazimuth(Pos)
        i = np.arccos(self.q)
        vmap = self.vsys + self.vprof(radii) * np.cos(phi) * np.sin(i) # v
        
        return vmap
    
    def vprof(self,radii):
        """ """
        if hasattr(self,'v'): v = self.v
        return np.zeros_like(radii) + v
        
    def sigmaprof(self,radii):
        if hasattr(self,'sigma'): sigma = self.sigma
        return np.zeros_like(radii) + sigma
    
    
    def getazimuth(self,Pos):
        """ """
        return rad.azimuth_mask(Pos,self.Cen,self.pa)
        
    
class KeplerDisk(KinoDisk):
    """Keplerian Disk"""
    
    def __init__(self,v,r,Cen,pa=0,q=1,c=0):
        """ """
        
        super(Keplerdisk,self).__init__(Cen,pa,q,c)
        self.Type = 'Kepler'
        self.v = v
        self.r = r
        
    def vprof(self,radii):
        """ """
        v = kepler(radii,self.v,self.r)
        return v
    
    
class Flatdisk(KinoDisk):
    """Flat Rotation Curve Disk"""
    
    def __init__(self,v,Cen,pa=0,q=1,c=0):
        """ """
        
        super(Flatdisk,self).__init__(Cen,pa,q,c)
        self.Type = 'FlatDisk'
        self.v = v
        
    def vprof(self,radii):
        """ """
        return np.zeros_like(radii) + self.v
    
    

# A minimal test is run when this file is run as a main program.
if __name__ == '__main__':
    print("Testing the module\n")
    # Basic code/example test
    print("Test finished.")

